@echo off
rem    -----------------------------------------------------------------------------
rem   |										    									|
rem   |	   	 Commandline tool to run ANT build script for RZT WS framework          |
rem   |										    									|
rem    -----------------------------------------------------------------------------

rem ------ SET PROJECT-SPECIFIC VARIABLES HERE -------
 
Set TOMCAT_HOME=C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.14
set PROJECT_BUILDFILE_PATH=C:\Users\rzt\Desktop\RazorthinkHiresysSourcing\buildconfig\build
set LOGFILE_PATH=C:\Users\rzt\Desktop\rzt-build_log.log
Set WARFILE_NAME=ws
Set SERVER_TYPE=sourcing
set RZTUSER=rzt


rem ------ BUILDING STARTS FROM HERE -------

set ACTUAL_WARFILE=%WARFILE_NAME%_%SERVER_TYPE%

REM %TOMCAT_HOME%\bin\shutdown.bat
REM if exists %TOMCAT_HOME%\webapps\%ACTUAL_WARFILE%.war del /s /F /Q "%TOMCAT_HOME%\webapps\%ACTUAL_WARFILE%" "%TOMCAT_HOME%\webapps\%ACTUAL_WARFILE%.war"
REM %TOMCAT_HOME%\bin\startup.bat
REM if exist "%TOMCAT_HOME%\webapps\%ACTUAL_WARFILE%.war" call "%TOMCAT_HOME%\bin\startup.bat"
REM netstat -na | find "LISTENING" | find /C /I "[::]:8080" > NUL
REM if %errorlevel%==0 call "%TOMCAT_HOME%\bin\startup.bat"


rem ------ Check if Tomcat is running -------
netstat -na | find "LISTENING" | find /C /I "[::]:8080" > NUL
if %errorlevel%==0 call "%TOMCAT_HOME%\bin\shutdown.bat"
call "%TOMCAT_HOME%\bin\shutdown.bat"
REM taskkill /T /F /IM java.exe
echo ---------------------------------------------------------------------------------- >> %LOGFILE_PATH%
echo %DATE% at %TIME% >> %LOGFILE_PATH%
echo Deleting old warfile - %TOMCAT_HOME%\webapps\%ACTUAL_WARFILE% >> %LOGFILE_PATH%
echo Deleting old application directory - %TOMCAT_HOME%\webapps\%ACTUAL_WARFILE% >> %LOGFILE_PATH%
rmdir /s /Q "%TOMCAT_HOME%\webapps\%ACTUAL_WARFILE%"
del /s /F /Q "%TOMCAT_HOME%\webapps\%ACTUAL_WARFILE%.war"
cd %PROJECT_BUILDFILE_PATH%
call "%TOMCAT_HOME%\bin\startup.bat"
ant shortbuild -Dwarname=%WARFILE_NAME% -DserverType=%SERVER_TYPE% >> %LOGFILE_PATH%
